
# -*- coding: utf-8 -*-
import datetime
import time
import sched
import os,pwd,time,datetime
import pandas as pd

names = ["hantianwen", "xiejiaxin", "hanhaoran"]
today = int(time.mktime(datetime.date.today().timetuple())) - 24*3600
#today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d')
#start_time = today + 'T00:00:00Z'
#end_time = today + 'T23:00:00Z'
def items_dir(rootnames = []):
    u = {}
    for rootname in rootnames:
        for main_dir, dirs, file_name_list in os.walk(rootname):
            for file in file_name_list:
                file_path = os.path.join(main_dir,file)
                stats = os.stat(file_path)
                if stats.st_ctime< today or stats.st_mtime <  today:
                    continue

                creator = pwd.getpwuid(stats.st_uid).pw_name
                if creator not in u:
                    u[creator] = []
                u[creator].append({
                    "file": file_path,
                    "time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stats.st_mtime))
                    })
    return u

def doStatics():
    global today
    files = items_dir(["./A-Logo", "B-客户端", "C-官网落地页", "D-活动", "E-广告", "F-物料"])
    list1 = []
    for key, v in files.items():
        vvv = {}
        vvv["开发者"] = key
        vvv["文件数"] = len(v)
        vvv["日期"] = time.strftime('%Y-%m-%d', time.localtime(today))
        list1.append(vvv)

    today = time.strftime('%Y-%m-%d', time.localtime(today))
    csvName = './tongji/sheji' + today + '.csv'
    df_u = pd.DataFrame(list1, columns=["开发者","文件数", "日期"])
    df_u.to_csv(csvName, index=False, encoding="utf_8_sig")

def time_printer():
    now = datetime.datetime.now()
    ts = now.strftime('%Y-%m-%d %H:%M:%S')
    print('do func time :', ts)
    loop_monitor()
def loop_monitor():
    s = sched.scheduler(time.time, time.sleep)  # 生成调度器
    s.enter(60, 1, time_printer, ())
    s.run()

if __name__ == "__main__":
    loop_monitor()